package xcmg.device.service.warehouse.allot;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import xcmg.device.dao.entity.warehouse.allot.RegionAllotPlanDetailDO;
import xcmg.device.dao.mapper.warehouse.RegionAllotPlanDetailMapper;
import xcmg.device.infra.BeanUtil;
import xcmg.device.service.warehouse.allot.vo.RegionAllotPlanDetailVO;
import yb.ecp.fast.feign.FastGenClient;

import java.util.List;

/**
 * 区域调拨计划详情 后台接口实现类
 */
@Slf4j
@Service
public class RegionAllotPlanDetailService {

    @Autowired
    private RegionAllotPlanDetailMapper regionAllotPlanDetailMapper;

    @Autowired
    private FastGenClient fastGenClient;

    public List<RegionAllotPlanDetailVO> queryByFK(String headerId) {
        RegionAllotPlanDetailVO vo = RegionAllotPlanDetailVO.builder().headerId(headerId).build();
        List<RegionAllotPlanDetailDO> ll = regionAllotPlanDetailMapper.queryList(vo);
        return BeanUtil.do2bo4List(ll, RegionAllotPlanDetailVO.class);
    }

    public int deleteByFK(String headerId) {
        return regionAllotPlanDetailMapper.deleteByHeaderId(headerId);
    }

    public int batchAdd(List<RegionAllotPlanDetailDO> doList) {
        if (CollectionUtils.isEmpty(doList)) {
            return 0;
        }
        int c = 0;
        for (RegionAllotPlanDetailDO detailDO : doList) {
            c += regionAllotPlanDetailMapper.insert(detailDO);
        }
        return c;
    }

    public List<RegionAllotPlanDetailDO> queryListByIds(List<String> ids) {
        return regionAllotPlanDetailMapper.queryListByIds(ids);
    }

    public List<RegionAllotPlanDetailVO> queryVoListByIds(List<String> ids) {
        return BeanUtil.do2bo4List(queryListByIds(ids), RegionAllotPlanDetailVO.class);
    }

    public int update(RegionAllotPlanDetailDO ddo) {
        return regionAllotPlanDetailMapper.updateByPrimaryKeySelective(ddo);
    }
}
